'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:ContractGccontractCtrl
 * @description
 * # ContractGccontractCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('ContractGccontractCtrl', function($scope,$location ,$rootScope, openApi, $http, Util, $routeParams, FormSubmit) {
        $scope.param = {};
        $scope.sheetObj = {};
        // 底部关联模块类型选框添加
        var projectTypeObj = {},
            selectData, params;
        projectTypeObj.sheettitle = "工程类型";
        projectTypeObj.callback = function(item) {
            $scope.param.projectType = item.selectTab
            $scope.param.projectTypeContent = item.selectTabContent
        }
        $scope.sheetObj.projectTypeObj = projectTypeObj;
        $scope.showprojectTypeObj = function() {
            var param = {};
            param.type = "工程类型";
            Util.getKeyValue(param, function(data) {
                $scope.sheetObj.projectTypeObj.tabList = data.data
                $scope.showSheet("projectTypeObj")
            })

        };
        $scope.showSheet = function(type) {
            var sheetObj = $scope.sheetObj[type]
            $scope.sheetObj.type = type
            $scope.sheetObj.tabList = sheetObj.tabList
            $scope.sheetObj.sheettitle = sheetObj.sheettitle
            $scope.sheetObj.ifshowSheet = true
            $rootScope.showMasker = true
        };
        $scope.choosePeople = function() {
            var relModuleObj = {
                name: "ContractGccontractCtrl",
                selectTab: "select_bid_by_contract",
                selectTabContent: "工程名称"
            };
            // 将列表的数据序列化存入缓存以便回来时候使用
            Util.savaParamForReview($scope.param, $routeParams.id);
            Util.savaDataforsearch(relModuleObj);
            $location.path("finance/choosepeople")
        };

        $scope.submit = function() {
            if (!$scope.param.developer) {
                Util.Toast("请填写建筑单位");
                return;
            }
            if (!$scope.param.projectName) {
                Util.Toast("请填写工程名称");
                return;
            }
            if (!$scope.param.contractAmount) {
                if ($scope.param.contractAmount !== 0) {
                    Util.Toast("请填写合同金额");
                    return;
                }
            }
            if (!$scope.param.projectType) {
                Util.Toast("请选择工程类型");
                return;
            }
            if (!$scope.param.projectManager) {
                Util.Toast("请填写建造师");
                return;
            }
            if (!$scope.param.dateOfSigning) {
                Util.Toast("请选择合同签订日期");
                return;
            }
            if (!$scope.param.startWorkingDate) {
                Util.Toast("请选择计划起始日期");
                return;
            }
            if (!$scope.param.endWorkingDate) {
                Util.Toast("请选择计划竣工日期");
                return;
            }
            // 提交
            var urlParam = "?operationId=-2" + "&&processId=" + $routeParams.id + "&&url=" + openApi.contractApply
            var options = {};
            options.urlParam = urlParam;
            options.param = $scope.param
            var TVtype;
            TVtype = Util.getTVType(); //根据页面的来源来判断是发起的流程还是修改的流程，如果是发起的则不管，如果是修改的则获取数据用来回显
            // 如果是修改页面的话则提交的地址不一样，参数一样
            if (TVtype == Util.UPDATE) {
                options.url = openApi.ip + openApi.contractApply
            }
            new FormSubmit(options);
        };
        var init = function() {
            // 获取回显的详细信息
            Util.getDetailData($routeParams.id, function(data) {
                $scope.param = data;
            });
            // 显示审批记录判断
            Util.showloglist($routeParams.id, function(data) {
                $scope.logData = data;
            });
        };
        // 初始化
        init();

    });
